package org.ysu.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ysu.common.JsonResult;

import org.ysu.pojo.Verifier;

import org.ysu.service.VerifierService;

@RestController
@RequestMapping("/verifier")
public class VerifierController {

    @Autowired
    VerifierService verifierService;


    @RequestMapping("getAllVerifier")
    public Object getAllVerifier() {
        return verifierService.getAllVerifier();
    }

    /**
     * 将clue表中的v_id=vid1的行的v_id改为vid2
     * @param vid1
     * @param vid2
     * @return
     */
    @PostMapping("/changemaster/{vid1}/{vid2}")
    public JsonResult changeMaster(@PathVariable Integer vid1,@PathVariable Integer vid2){
        Integer hang =verifierService.changeMaster(vid1,vid2);
        JsonResult jsonResult =new JsonResult(1,"success",hang);
        return jsonResult;
    }

    /**
     * 获取折线图所需数据
     * @param vId
     * @return
     */

    @RequestMapping("/selectByVid/{vId}")
    public Verifier selectByVid( @PathVariable("vId") Integer vId) {
        System.out.println("v_id:" + vId);
        return verifierService.selectByVid(vId);
    }


    @RequestMapping("getInterviews/{data}")
    public JsonResult getInterviews(@PathVariable Integer data) {
        //获取近data天，每个人每天提供了多少走访信息
        return new JsonResult(1, "success", verifierService.getInterviews(data));
    }


    /**
     * 获取日历图u所需数据
     */
    @RequestMapping("getCalendar/{data}")
    public JsonResult getCalendar(@PathVariable Integer data) {
        //所需数据为一个数组，包括yyyy-MM-dd格式的日期和该日期对应的走访次数
        return new JsonResult(1, "success", verifierService.getCalendar(data));
    }

    /**
     * 获取统计数据
     */
    @RequestMapping("getStatistic")
    public JsonResult getStatistic() {
        return new JsonResult(1, "success", verifierService.getStatistic());
    }

    /**
     * 获取柱状图数据
     */
    @RequestMapping("getBarData/{data}")
    public JsonResult getBarData(@PathVariable Integer data) {
        return new JsonResult(1, "success", verifierService.getBarData(data));
    }

    /**
     * 获取地图数据
     */
    @RequestMapping("/getMapData/{place}")
    public JsonResult getMapData(@PathVariable String  place) {
        return new JsonResult(1, "success", verifierService.getMapData(place));
    }

}
